import requests
import os

IPADDRESS = "localhost" #Replace this with the correct IP address
UNSTRUCTURED_DATA_PORT = "8086"
# URL of the API endpoint
url = f'http://{IPADDRESS}:{UNSTRUCTURED_DATA_PORT}/documents'
# Path to the PDF file you want to upload
directory_path = '../data/manuals_pdf'

# Loop through all files in the directory
for filename in os.listdir(directory_path):
    # Check if the file is a PDF
    if filename.endswith('.pdf'):
        file_path = os.path.join(directory_path, filename)

        # Open the file in binary mode and send it in a POST request
        with open(file_path, 'rb') as file:
            files = {'file': file}
            response = requests.post(url, files=files)

        # Print the response from the server
        print(f'Uploaded {filename}: {response.status_code}')
        print(response.json())